/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package swimsystem;

import javax.swing.UnsupportedLookAndFeelException;
import org.freixas.jwizard.JWizardDialog;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.DefaultListModel;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.UIManager;
import org.freixas.jwizard.JWizardPanel;
import java.util.logging.Logger;
import java.util.logging.Level;
import java.sql.*;

/**
 *
 * @author Luis Preciado
 */
public class Main extends JWizardDialog{

    /**
     * @param args the command line arguments
     */
    Step0 s0 = new Step0();
    Step1 s1 = new Step1();
    Step2 s2 = new Step2();

    static Connection con;
    static Statement stat;
    static ResultSet rs;
    static String error;
    
    public static void main(String[] args) throws UnsupportedLookAndFeelException
    {
        try {
            // TODO code application logic here
            UIManager.setLookAndFeel("com.nilo.plaf.nimrod.NimRODLookAndFeel");
            new Main();
            System.exit(0);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
        new Main();
        System.exit(0);
        
    }
    public Main()
        {           
            // Solo se muestra el JWizard no permite el uso de otra ventana.   
            setModal(true);
            setTitle("Nuevo Usuario");
            URL url = getClass().getResource("/doc/example/Example1.gif");
            setWizardIcon(new ImageIcon(url));
//            addWizardPanel(new Step0());
//            addWizardPanel(new Step1());
//            addWizardPanel(new Step2());
//            addWizardPanel(new Step3());
            addWizardPanel(s0);
            addWizardPanel(s1);
            addWizardPanel(s2);
            disableCancelAtEnd();
            pack();
            setVisible(true);     
        }
    private class Step0 extends JWizardPanel
    {
        public Step0()
        {
            setVisible(true);
            setStepTitle("SWIM SYSTEM");
            JPanel contentPane = getContentPane();
            contentPane.setLayout(new BorderLayout());
//            JPanel MiPanel = new JPanel();
//            MiPanel.add(MiPanel);
            
            JLabel Titulo = new JLabel("INSTALACIÓN SWIM SYSTEM");
//            contentPane.add(MiPanel,BorderLayout.NORTH);
            contentPane.add(Titulo);
            
            pack();
            setBackStep(-1);
            setNextStep(1);
        }
    }
        
        
        private class Step1 extends JWizardPanel
    {     
            JTextField txtIdUser = new JTextField();
        JTextField txtNombre = new JTextField();
        JTextField txtContra = new JTextField();
    public Step1()
    {
        setStepTitle("Registro del Usuario");
        JPanel contentPane = getContentPane();
        contentPane.setLayout(new GridLayout(3,2));       
        
        //LABELS
        JLabel IdUsuario = new JLabel("Id Usuario:");        
        JLabel Nombre = new JLabel("Nombre:");
        JLabel Contra = new JLabel("Contraseña:");
              
        
        
        
        //JPanel MiPanel = new JPanel();
        contentPane.setLayout(new GridLayout(3,2));
        contentPane.add(IdUsuario);
        contentPane.add(txtIdUser);
        contentPane.add(Nombre);
        contentPane.add(txtNombre);
        contentPane.add(Contra);
        contentPane.add(txtContra);
        
       

        if(txtIdUser.getText().length()>0) 
            //Equals
        {
            setNextStep(2);
        }
        pack();
        setNextStep(2);
        setBackStep(0);
    }
    }
            private class Step2 extends JWizardPanel
            {
              private JLabel label;
              public Step2()
            {
            setStepTitle("Fin de la Instalacion");
            JPanel contentPane = getContentPane();
            contentPane.setLayout(new BorderLayout());
            label = new JLabel();
            contentPane.add(label,BorderLayout.NORTH);
            setBackStep(1);
            pack();
            }
              
            }
            public void finish()
                    {
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();         
        } catch( Exception e ) {
            JOptionPane.showMessageDialog(null,"No se pudo cargar el puente JDBC-ODBC.");
        }    
        try {
            con = DriverManager.getConnection("jdbc:mysql://localhost/Swim", "root", "abc321");
            stat = con.createStatement();
            stat.execute("Insert into Usuarios values ('" + s1.txtIdUser.getText() + "','" + s1.txtNombre.getText() + "','" + s1.txtContra.getText() + "')");
            con.close();
            JOptionPane.showMessageDialog(null, "Regisrado");
            this.dispose();
        } catch (SQLException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
            }

}
